﻿using Domain.Types;
using Domain.VO;
using Infrastructure.AggregateBase;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;

namespace Domain.Model
{
    [Table("TaskTake")]//ITaskTakeRepository
    public class TaskTakeAggregate : AggregateRoot<TaskTakeAggregate, int>
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public override int ID { get; set; }

        //public virtual TaskSrcDataVO TaskSrcData { get; set; }
        public int TaskID { get; set; }
        /// <summary>
        /// 字段数据
        /// </summary>
        [StringLength(2000)]
        public string FieldData { get; set; }
        /// <summary>
        /// 任务步骤数据
        /// </summary>
        [StringLength(2000)]
        public string StepFieldData { get; set; }
        /// <summary>
        /// 提交表单名称
        /// </summary>
        [StringLength(50)]
        public string SubFieldName { get; set; }
        public LimitTimeEnum TakeLimitTime { get; set; }
        public LimitAuditEnum TakeLimitAudit { get; set; }
        public int Price { get; set; }

        [StringLength(2000)]
        public string FromData { get; set; }
        public int UserID { get; set; }
        public TaskTakeAuditStatus Status { get; set; }
        [StringLength(1000)]
        public string StatusInfo { get; set; }

        /// <summary>
        /// 超时时间,超时后领取的任务作废
        /// </summary>
        public DateTime OutTime { get; set; }

        public DateTime? AuditOutTime { get; set; }
        /// <summary>
        /// 审核完成时间
        /// </summary>
        [Timestamp]
        public byte[] RowVersion { get; set; }

        /// <summary>
        /// 完成后是否处理支付与佣金
        /// </summary>        
        public bool IsHandlePay { get; set; }
        /// <summary>
        /// 处理支付时间
        /// </summary>
        public DateTime? HandlePayTime { get; set; }
        /// <summary>
        /// 处理信息
        /// </summary>
        [StringLength(1000)]
        public string HandleInfo { get; set; }
        /// <summary>
        /// 预估收入
        /// </summary>
        public int PreFee { get; set; }
        public int TaskUserID { get; set; }
        public DateTime? AuditFinishTime { get; set; }

        public List<TaskStepFieldInfo> GetStepDataField()
        {
            if (string.IsNullOrWhiteSpace(StepFieldData)) return null;

            return JsonConvert.DeserializeObject<List<TaskStepFieldInfo>>(StepFieldData);
        }

        public List<TaskFieldInfo> GetDataField()
        {
            if (string.IsNullOrWhiteSpace(FieldData)) return null;

            return JsonConvert.DeserializeObject<List<TaskFieldInfo>>(FieldData);
        }
    }
}
